package com.abel.day0306;

import java.util.Arrays;

/**
 * @author xiachao
 * @date 2019/3/6
 */
public class Solution {

    public int GetUglyNumber_Solution(int index) {
        if(index == 1){
            return 1;
        }
        int cur = 1;
        int num = 2;

        while(true){
            int t = num;
            while(t%2==0) t /= 2;
            while(t%3==0) t /= 3;
            while(t%5==0) t /= 5;
            if(t==1){
                if(++cur == index){
                    return num;
                }
            }
            num++;
        }
    }

    public int GetNumberOfK(int [] array , int k) {
        if(array.length == 0){
            return 0;
        }
        int count = 0;
        int index = Arrays.binarySearch(array, k);
        if(index < 0){
            return 0;
        }
        for(int i = index;i>=0;i--){
            if(array[i]!=k){
                break;
            }
            count++;
        }
        for(int i=index+1;i<array.length;i++){
            if(array[i]!=k){
                break;
            }
            count++;
        }

        return count;
    }

    public static void main(String[] args) {
        //System.out.println(new Solution().GetUglyNumber_Solution(6));
        int [] arr = {1,3,3,3,3,4,5};
        System.out.println(new Solution().GetNumberOfK(arr, 2));
    }

}
